package demoMod.invincibleOne.powers;

import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.actions.unique.LoseEnergyAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.AbstractCreature;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.localization.PowerStrings;
import com.megacrit.cardcrawl.powers.AbstractPower;
import com.megacrit.cardcrawl.powers.NoDrawPower;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.enums.CardTagsEnum;
import demoMod.invincibleOne.interfaces.IOnCurseAddToHand;

public class DifficultyBreathingPower extends AbstractPower implements IOnCurseAddToHand {
    public static final String POWER_ID = InvincibleOneMod.makeID("DifficultyBreathingPower");
    private static final PowerStrings powerStrings = CardCrawlGame.languagePack.getPowerStrings(POWER_ID);
    public static final String NAME = powerStrings.NAME;
    public static final String[] DESC = powerStrings.DESCRIPTIONS;
    private final int initAmount;

    private static int idOffset = 0;

    public DifficultyBreathingPower(AbstractCreature owner, int amount) {
        this.owner = owner;
        this.ID = POWER_ID + idOffset;
        idOffset++;
        this.name = NAME;
        this.amount = this.initAmount = amount;
        this.updateDescription();
        loadRegion("painfulStabs");
        this.type = PowerType.DEBUFF;
    }

    @Override
    public void updateDescription() {
        this.description = String.format(DESC[0], this.amount);
    }

    @Override
    public void onCardDraw(AbstractCard card) {
        if (card.type == AbstractCard.CardType.CURSE || card.hasTag(CardTagsEnum.VIRUS)) {
            onCurseAddToHand(card);
        }
    }

    @Override
    public void onCurseAddToHand(AbstractCard c) {
        if (this.amount > 1) {
            this.amount = this.amount - 1;
        } else {
            this.flash();
            this.amount = this.initAmount;
            addToBot(new LoseEnergyAction(1));
        }
        updateDescription();
    }
}
